import { uploadFileOss } from "@/utils/upload";
import { Icon, View, Image } from "@tarojs/components";
import Taro from "@tarojs/taro";
import { useState } from "react";

export default function Index() {
  const [urls, setUrls] = useState<string[]>([]);

  const onClick = async () => {
    try {
      const result = await Taro.chooseImage({
        // count: 9,
        sizeType: ["original", "compressed"],
        sourceType: ["album", "camera"],
      });

      for (let file of result.tempFiles) {
        console.log(file);
        const url = await uploadFileOss(file.path);
        console.log(url);
        setUrls((us) => us.concat(url));
      }
    } catch (err) {
      console.log(err);
      Taro.showToast({ title: err?.errMsg, icon: "error", duration: 2000 });
    }
  };

  return (
    <>
      <View className="font-semibold text-lg sticky top-0 bg-white p-4 z-10">
        dqwdw
      </View>
      <View className="px-4">
        <View className="flex border-b border-gray-600 py-1">
          <View className="w-28">调整日期</View>
          <View className="flex-1">1年期</View>
          <View className="flex items-center">5年期</View>
        </View>
        <Icon size={60} type="success" onClick={onClick} />
        {urls.map((u, index) => (
          <Image src={u} key={index} />
        ))}
      </View>
    </>
  );
}
